namespace RealtimeCollabGame.Domain.ValueObjects;

public record PlayerColor(string Value)
{
    private static readonly string[] PredefinedColors = {
        "#FF0000", // 红色
        "#00FF00", // 绿色
        "#0000FF", // 蓝色
        "#FFFF00", // 黄色
        "#FF00FF", // 洋红
        "#00FFFF", // 青色
        "#FFA500", // 橙色
        "#800080", // 紫色
        "#008000", // 深绿
        "#FFC0CB"  // 粉色
    };
    
    public static PlayerColor Red => new("#FF0000");
    public static PlayerColor Blue => new("#0000FF");
    public static PlayerColor Green => new("#00FF00");
    public static PlayerColor Yellow => new("#FFFF00");
    
    public static PlayerColor GetRandomColor()
    {
        var random = new Random();
        var color = PredefinedColors[random.Next(PredefinedColors.Length)];
        return new PlayerColor(color);
    }
    
    public static List<PlayerColor> GetDistinctColors(int count)
    {
        if (count > PredefinedColors.Length)
            throw new ArgumentException($"最多支持{PredefinedColors.Length}种颜色");
            
        var colors = new List<PlayerColor>();
        var availableColors = new List<string>(PredefinedColors);
        var random = new Random();
        
        for (int i = 0; i < count; i++)
        {
            var index = random.Next(availableColors.Count);
            colors.Add(new PlayerColor(availableColors[index]));
            availableColors.RemoveAt(index);
        }
        
        return colors;
    }
    
    public static implicit operator string(PlayerColor color) => color.Value;
    
    public override string ToString()
    {
        return Value;
    }
} 